/**
 * @file MainGuiQml.cpp
 * @author rui.liang (rui.liang@ruhnix.com)
 * @brief 
 * @version 1.0
 * @date 2025-10-18
 * 
 * @copyright Copyright (c) 2025
 * 
 */

#include "MainGuiQml.h"

#include <QQmlApplicationEngine>
#include <QQmlContext>

#include "Backend.hpp"

MainGuiQml::Ptr MainGuiQml::create() {
    Backend *backend = new Backend();
    QQmlApplicationEngine *engine = new QQmlApplicationEngine();
    engine->rootContext()->setContextProperty("backend", backend);
    engine->loadFromModule(u"App"_qs, u"Main"_qs);
    if (engine->rootObjects().isEmpty()) {
        return nullptr;
    }
    std::shared_ptr<MainGuiQml> instance(new MainGuiQml(engine, backend));
    return instance;
}

MainGuiQml::MainGuiQml(QQmlApplicationEngine *engine, Backend *backend)
    : m_engine(engine), m_backend(backend) {}

int MainGuiQml::exec(QApplication &app) { return app.exec(); }
